use tokio::sync::mpsc::{UnboundedSender, UnboundedReceiver};

pub(crate) struct Probe (UnboundedSender<odin_service::ServiceProbeStatus>);

impl odin_service::ServiceProbe for Probe {
    fn report_status(&self, status: odin_service::ServiceProbeStatus) {
        self.0.send(status).unwrap_or_default();
    }
}

pub(crate) struct ServiceStatusController {
    status_tx: UnboundedSender<odin_service::ServiceProbeStatus>,
    status_rx: UnboundedReceiver<odin_service::ServiceProbeStatus>,
}

impl ServiceStatusController {
    pub(crate) fn new() -> Self {
        let (status_tx, status_rx) = tokio::sync::mpsc::unbounded_channel();

        Self {
            status_tx,
            status_rx,
        }
    }

    pub(crate) fn probe(&self) -> Probe {
        Probe(self.status_tx.clone())
    }
}
